package com.kingbook.api.rest;

import com.kingbook.common.utils.StringUtils;
import com.kingbook.core.auth.LoginManager;
import com.kingbook.core.result.JSONResult;
import com.kingbook.services.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.kingbook.core.auth.LoginManager.AUTH;

/**
 * @Author Bucky
 * @Date 2019-12-08 17:18:13
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("report")
public class ReportRest {

    @Autowired
    ReportService reportService;

    @GetMapping("rank/{type}")
    public JSONResult rankList(@PathVariable int type, @RequestHeader(name = AUTH) String auth) {
        int mid = LoginManager.getMid(auth);
        log.info("---->mid={} type={}", mid, type);
        return reportService.rankList(type, mid);
    }

    @GetMapping("profit")
    public JSONResult profit(@RequestHeader(name = AUTH) String auth) {
        int mid = LoginManager.getMid(auth);
        log.info("---->mid={}", mid);
        return reportService.profit(mid);
    }

    @GetMapping("expend/{month}")
    public JSONResult expend(@PathVariable String month, @RequestHeader(name = AUTH) String auth) {
        int mid = LoginManager.getMid(auth);
        log.info("---->mid={} month={}", mid, month);
        if (StringUtils.isEmpty(month) || month.length() != 7) {
            return JSONResult.failed("月份格式错误");
        }
        return reportService.expend(month, mid);
    }

    @GetMapping("confirmRate")
    public JSONResult confirmRate(@RequestHeader(name = AUTH) String auth) {
        int mid = LoginManager.getMid(auth);
        log.info("---->mid={}", mid);
        return reportService.confirmRate(mid);
    }


}
